local sys = System.new()
sys.pressed = false
sys.pressedButtons = {}

function sys:touchpressed()

end

function sys:touchmoved()

end

function sys:touchreleased()

end

function sys:mousepressed(x, y, button, istouch, presses)
    self.pressedButtons[button] = true
    Node.Root:mousepressed(x, y)
end

function sys:mousemoved(x, y)
    EventDispatcher.global:emit(NodeEvent.MouseMoved, x, y)
    Node.Root:mousemoved(x, y)
end

function sys:mousereleased(x, y, button, istouch, presses)
    EventDispatcher.global:emit(NodeEvent.MouseReleased, x, y)
    Node.Root:mousereleased(x, y)
end

function sys:resize(w, h)
    EventDispatcher.global:emit(GlobalEvent.WindowResized, w, h)
end

function sys:keypressed(k)
    if k == "space" then
        if RenderSystem.pasued then
            RenderSystem:_draw()
        end
        RenderSystem.pasued = true
    elseif k == "return" then
        if Global.focused and Global.focused.unfocus then
            Global.focused:unfocus()
            Global.focused = nil
        end
    elseif k == "backspace" then
        if Global.focused and Global.focused.backspace then
            Global.focused:backspace()
        end
    else
        if Global.focused and Global.focused.input then
            Global.focused:input(k)
        end
    end

    if love.keyboard.isDown("lctrl") and k == "s" then
        Editor.gameManager:Save()
    end
    if love.keyboard.isDown("lctrl") and k == "o" then
        Editor.gameManager:load("helloWorld")
    end
end

function love.textedited(text, start, length)
    if Global.focused and Global.focused.set then
        if start == 0 and length == 0 then
            -- FocusTextEditor:unfocus()
            -- FocusTextEditor = nil
        else
            FocusTextEditor:set(text)
        end
    end
end

function love.textinput(text)
    if Global.focused and Global.focused.input then
        Console.log("textinput", Global.focused.name, text)
        Global.focused:input(text)
    end
end

RegisterSystem(sys)